package com.zxy.lm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxy.lm.entity.Book;
import com.zxy.lm.mapper.BookMapper;
import com.zxy.lm.service.BookService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jiusi
 * @since 2021-06-22
 */
@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {

    @Autowired
    private BookMapper bookMapper;

    @Override
    public List<Book> queryAllBook() {
        return baseMapper.selectList(null);
    }

    @Override
    public boolean decreaseBookStock(int bookId, int count) {
        Integer integer = bookMapper.decreaseBookStock(bookId, count);
        return integer > 0;
    }

    @Override
    public boolean increaseBookStock(int bookId, int count) {
        Integer integer = bookMapper.increaseBookStock(bookId, count);
        return integer > 0;
    }

    @Override
    public Book queryById(Integer bookId) {
        QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", bookId);
        return bookMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer getBookStockById(Integer bookId) {
        return bookMapper.selectBookStockById(bookId);
    }
}
